#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 2e6 + 10;
const int V = 1e6 + 10;

struct line {
	ll k, b;
	line(ll _k = 0, ll _b = -1e18) : k(_k), b(_b) {}
	ll operator [](ll x) { return k * x + b; }
} val[N << 2];

int n, a[N];
ll s[N];

void upd(line v, int o = 1, int l = -V, int r = V) {
	int mid = l + r >> 1; if(v[mid] > val[o][mid]) swap(v, val[o]); if(l == r) return;
	if(v[l] > val[o][l]) upd(v, o << 1, l, mid); if(v[r] > val[o][r]) upd(v, o << 1 | 1, mid + 1, r);
}

ll query(int pos, int o = 1, int l = -V, int r = V) {
	ll ans = val[o][pos]; if(l == r) return ans; int mid = l + r >> 1;
	if(pos <= mid) chkmax(ans, query(pos, o << 1, l, mid)); else chkmax(ans, query(pos, o << 1 | 1, mid + 1, r));
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in; ll ans = 0; rep(i, 1, n) a[i] = in, s[i] = s[i - 1] + a[i], ans += 1ll * i * a[i];
	ll delta = 0;
	rep(i, 1, n) {
		chkmax(delta, query(a[i]) + s[i - 1] - 1ll * i * a[i]);
		upd(line(i, -s[i - 1]));
	}
	rep(i, 1, (N << 2) - 1) val[i] = line();
	per(i, n, 1) {
		chkmax(delta, query(a[i]) + s[i] - 1ll * i * a[i]);
		upd(line(i, -s[i]));
	}
	printf("%lld\n", ans + delta);
	return 0;
}
